package step3;
 
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.Socket;
import java.net.SocketException;

class ReceiveThread extends Thread {
	DataOutputStream dos;
	DataInputStream dis;
	Socket s;
	public ReceiveThread(Socket s, DataOutputStream dos, DataInputStream dis) {
		this.s = s;
		this.dos = dos;
		this.dis = dis;
	}
	@Override
	public void run() {
		try {
			dos.writeUTF("请输入一个整数，我知道是奇数还是偶数");
			while(true) {
				String num = dis.readUTF();
				if("-1".equals(num)) {
					s.close();
					break;
				} 
				String result = (Integer.parseInt(num)%2==0)?"偶数":"奇数";
				dos.writeUTF(num + "是..." + result);
			}			
		} catch (SocketException e) {
			try {
				s.close();
			} catch (IOException e1) {
				e1.printStackTrace();
			}
		} catch (IOException e) {
			System.out.println("数据读取异常");
		} 
	}	
}